//
//  ShopCenterViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/25.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "ShopCenterViewController.h"

#import "ShopView.h"
#import "DPZLViewController.h"
#import "YJDViewController.h"
#import "DJDViewController.h"
#import "YWCViewController.h"
@interface ShopCenterViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong)NSArray *arr1Img;
@property (nonatomic,strong)NSArray *arr1Tit;
@property (nonatomic,strong)NSArray *arr1Det;
@property (nonatomic,strong)NSArray *arr2Img;
@property (nonatomic,strong)NSArray *arr2Tit;
@property (nonatomic,strong)NSArray *arr3Img;
@property (nonatomic,strong)NSArray *arr3Tit;
@property (nonatomic,strong)UITableView *tableView;

@end

@implementation ShopCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = COLOR_RGB(242, 242, 242, 1);

    _arr1Img = @[@"wdye",@"评论-1",@""];
    _arr1Tit = @[@"营业额",@"我的余额",@"店铺评论"];
    _arr1Det = @[@"1000元",@"200元",@"2222"];
    
    _arr2Img = @[@"商品管理-拷贝",@"053-店铺资料-拷贝"];
    _arr2Tit = @[@"商品管理",@"店铺资料"];
    
    _arr3Img = @[@"商品管理-拷贝",@"053-店铺资料-拷贝"];
    _arr3Tit = @[@"推广用户",@"推广骑手"];
    
    
    [self loadNav];
    [self loadUI];
    
}

- (void)loadNav{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 64)];
    view.backgroundColor = [UIColor whiteColor];
    view.userInteractionEnabled = YES;
    [self.view addSubview:view];
    
    UILabel *lab = [[UILabel alloc] init];
    lab.text = @"商家中心";
    lab.textColor = [UIColor blackColor];
    lab.font = [UIFont systemFontOfSize:18.0];
    [view addSubview:lab];
    [lab makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(view.centerX);
        make.top.equalTo(34);
    }];
    
    UILabel *line = [[UILabel alloc] init];
    line.backgroundColor = [UIColor lightGrayColor];
    [view addSubview:line];
    [line makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(0);
        make.right.equalTo(0);
        make.bottom.equalTo(view.bottom);
        make.height.equalTo(0.5);
    }];
    
    //返回按钮
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"箭头"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"箭头"] forState:UIControlStateHighlighted];
    [btn addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    [btn makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lab.centerY);
        make.left.equalTo(5);
        make.width.equalTo(30);
        make.height.equalTo(30);
    }];
    
    //按钮
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setImage:[UIImage imageNamed:@"消息2"] forState:UIControlStateNormal];
    [btn2 setImage:[UIImage imageNamed:@"消息2"] forState:UIControlStateHighlighted];
    [btn2 addTarget:self action:@selector(clickRight) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn2];
    [btn2 makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(lab.centerY);
        make.right.equalTo(-5);
        make.width.equalTo(30);
        make.height.equalTo(30);
    }];
    
}
// 返回
- (void)clickBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)clickRight{
    
}

- (void)loadUI{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, ScreenWidth, ScreenHeight-64) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    ShopView *view = [[[NSBundle mainBundle] loadNibNamed:@"ShopView" owner:nil options:nil] lastObject];
    view.frame = CGRectMake(0, 0, ScreenWidth, 220);
    _tableView.tableHeaderView = view;
    
    view.view1.layer.cornerRadius = 5.0;
    view.view1.layer.borderWidth = 0.5;
    view.view1.layer.borderColor = [UIColor blackColor].CGColor;
    
    view.view2.layer.cornerRadius = 5.0;
    view.view2.layer.borderWidth = 0.5;
    view.view2.layer.borderColor = [UIColor blackColor].CGColor;
    
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
#pragma -mark UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 3;
    }else if (section == 1 || section == 2){
        return 2;
    }
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        static NSString *cellId = @"Cell1";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        if (indexPath.row == 0) {
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
        cell.imageView.image = [UIImage imageNamed:_arr1Img[indexPath.row]];
        cell.textLabel.text = _arr1Tit[indexPath.row];
        cell.detailTextLabel.text = _arr1Det[indexPath.row];
        cell.textLabel.font = [UIFont systemFontOfSize:14.0];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:14.0];
        
        
        return cell;
    }else if (indexPath.section == 1){
        static NSString *cellId = @"Cell2";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.imageView.image = [UIImage imageNamed:_arr2Img[indexPath.row]];
        cell.textLabel.text = _arr2Tit[indexPath.row];
        cell.textLabel.font = [UIFont systemFontOfSize:14.0];
        
        
        return cell;
    }else if (indexPath.section == 2){
        static NSString *cellId = @"Cell3";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.imageView.image = [UIImage imageNamed:_arr3Img[indexPath.row]];
        cell.textLabel.text = _arr3Tit[indexPath.row];
        cell.detailTextLabel.text = @"aaa";
        cell.textLabel.font = [UIFont systemFontOfSize:14.0];
        
        return cell;
    }else{
        static NSString *cellId = @"Cell4";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.imageView.image = [UIImage imageNamed:@"客服"];
        cell.textLabel.text = @"客服中心";
        cell.textLabel.font = [UIFont systemFontOfSize:14.0];
        
        return cell;
    }
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            
        }else{
            DPZLViewController *dpzl = [[DPZLViewController alloc] init];
            [self.navigationController pushViewController:dpzl animated:YES];
        }
    }else{
        
    }
}

//头视图
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 100)];
        view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
        //待接单
        UIView *viewL = [[UIView alloc] initWithFrame:CGRectMake(0, 10, ScreenWidth/3, 80.0)];
        viewL.backgroundColor = [UIColor whiteColor];
        [view addSubview:viewL];
        
        UIImageView *image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"开关机_待接单"]];
        [viewL addSubview:image1];
        [image1 makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(viewL.centerX);
            make.top.equalTo(viewL.top).offset(10);
        }];
        
        UILabel *lab1 = [[UILabel alloc] init];
        lab1.text = @"待接单";
        lab1.font = [UIFont systemFontOfSize:15.0];
        [viewL addSubview:lab1];
        [lab1 makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(image1.centerX);
            make.top.equalTo(image1.bottom).offset(8);
        }];
        
        UILabel *line1 = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth/3, 20, 1, 60)];
        line1.backgroundColor = [UIColor grayColor];
        [view addSubview:line1];
        
        UILabel *line2 = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth/3*2, 20, 1, 60)];
        line2.backgroundColor = [UIColor grayColor];
        [view addSubview:line2];
        
        //已接单
        UIView *viewC = [[UIView alloc] initWithFrame:CGRectMake(ScreenWidth/3, 10, ScreenWidth/3, 80.0)];
        viewC.backgroundColor = [UIColor whiteColor];
        [view addSubview:viewC];
        
        UIImageView *image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"已接单"]];
        [viewC addSubview:image2];
        [image2 makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(viewC.centerX);
            make.top.equalTo(viewC.top).offset(10);
        }];
        
        UILabel *lab2 = [[UILabel alloc] init];
        lab2.text = @"已接单";
        lab2.font = [UIFont systemFontOfSize:15.0];
        [viewC addSubview:lab2];
        [lab2 makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(image2.centerX);
            make.top.equalTo(image2.bottom).offset(8);
        }];
        //已完成订单
        UIView *viewR = [[UIView alloc] initWithFrame:CGRectMake(ScreenWidth/3*2, 10, ScreenWidth/3, 80.0)];
        viewR.backgroundColor = [UIColor whiteColor];
        [view addSubview:viewR];
        
        UIImageView *image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"订单-1"]];
        [viewR addSubview:image3];
        [image3 makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(viewR.centerX);
            make.top.equalTo(viewR.top).offset(10);
        }];
        
        UILabel *lab3 = [[UILabel alloc] init];
        lab3.text = @"已完成订单";
        lab3.font = [UIFont systemFontOfSize:15.0];
        [viewR addSubview:lab3];
        [lab3 makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(image3.centerX);
            make.top.equalTo(image3.bottom).offset(8);
        }];
        viewL.userInteractionEnabled = YES;
        viewC.userInteractionEnabled = YES;
        viewR.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click1)];
        [viewL addGestureRecognizer:tap1];
        
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click2)];
        [viewC addGestureRecognizer:tap2];
        
        UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click3)];
        [viewR addGestureRecognizer:tap3];
        return view;
    }else if (section == 1){
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
        view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
        return view;
    }else{
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
        view.backgroundColor = COLOR_RGB(242, 242, 242, 1);
        return view;
    }
    
}

- (void)click1{
    DJDViewController *djd = [[DJDViewController alloc] init];
    [self.navigationController pushViewController:djd animated:YES];
}

- (void)click2{
    YJDViewController *yjd = [[YJDViewController alloc] init];
    [self.navigationController pushViewController:yjd animated:YES];
}

- (void)click3{
    YWCViewController *djd = [[YWCViewController alloc] init];
    [self.navigationController pushViewController:djd animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 100.0;
    }
    return 10;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
